package algotithm.leetcode.bit.test898;

import java.util.HashSet;
import java.util.Set;

/**
 * @author zhouyanxiang
 * @Date 2021-02-2021/2/3-21:38
 * @Title 898. 子数组按位或操作
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] arr = {1,1,2};
        int i = solution.subarrayBitwiseORs(arr);
        System.out.println(i);
    }

    public int subarrayBitwiseORs(int[] arr) {
        Set<Integer> set = new HashSet<>(65535);
        for (int i = 0; i < arr.length; i++ ) {
            set.add(arr[i]);
            for (int j = i - 1; j >= 0; j--) {
                if ((arr[j] | arr[i]) == arr[j]) {
                    break;
                }
                arr[j] |= arr[i];
                set.add(arr[j]);
            }
        }
        return set.size();
    }
}
